﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Project.Yan.Net.Redis.RedisBase
{
    /// <summary>
    /// 定义了一个用于操作Redis存储库的接口
    /// </summary>
    public interface IRedisRepository
    {
        /// <summary>
        /// 异步获取指定键的字符串值
        /// </summary>
        /// <param name="key">要获取值的键</param>
        /// <returns>返回键对应的字符串值</returns>
        Task<T> GetAsync<T>(string key);

        /// <summary>
        /// 异步批量获取 Redis 中指定键的字符串值，并返回
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keys"></param>
        /// <returns></returns>
        Task<Dictionary<string, T>> GetsAsync<T>(List<string> keys);
        /// <summary>
        /// 异步获取指定键的字符串值
        /// </summary>
        /// <param name="key">要获取值的键</param>
        /// <returns>返回键对应的字符串值</returns>
        Task<string> GetStringAsync(string key);
        /// <summary>
        /// 异步设置指定键的字符串值
        /// </summary>
        /// <param name="key">要设置值的键</param>
        /// <param name="value">要设置的字符串值</param>
        /// <returns>返回任务对象</returns>
        Task SetStringAsync(string key, string value,TimeSpan? expiry = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        Task SetAsync(string key, object value, TimeSpan? expiry = null);
        /// <summary>
        /// 异步获取哈希表中指定键和字段的值
        /// </summary>
        /// <param name="key">哈希表的键</param>
        /// <param name="field">哈希表中的字段</param>
        /// <returns>返回字段对应的字符串值</returns>
        Task<string> GetHashFieldAsync(string key, string field);

        /// <summary>
        /// 异步设置哈希表中指定键和字段的值
        /// </summary>
        /// <param name="key">哈希表的键</param>
        /// <param name="field">哈希表中的字段</param>
        /// <param name="value">要设置的字符串值</param>
        /// <returns>返回任务对象</returns>
        Task SetHashFieldAsync(string key, string field, string value);

        /// <summary>
        /// 异步检查指定键是否存在
        /// </summary>
        /// <param name="key">要检查的键</param>
        /// <returns>如果键存在返回true，否则返回false</returns>
        Task<bool> KeyExistsAsync(string key);

        /// <summary>
        /// 异步删除指定键
        /// </summary>
        /// <param name="key">要删除的键</param>
        /// <returns>返回任务对象</returns>
        Task DeleteKeyAsync(string key);


        /// <summary>
        /// 异步将值追加到列表尾部
        /// </summary>
        /// <param name="key">列表的键</param>
        /// <param name="value">要追加的值</param>
        /// <returns>返回任务对象</returns>
        Task AppendToListAsync(string key, string value);

        /// <summary>
        /// 异步从列表中移除并返回第一个元素
        /// </summary>
        /// <param name="key">列表的键</param>
        /// <returns>返回列表中第一个元素</returns>
        Task<string> PopFromListLeftAsync(string key);

        /// <summary>
        /// 异步从列表中移除并返回最后一个元素
        /// </summary>
        /// <param name="key">列表的键</param>
        /// <returns>返回列表中最后一个元素</returns>
        Task<string> PopFromListRightAsync(string key);

        /// <summary>
        /// 异步将一个或多个成员添加到集合中
        /// </summary>
        /// <param name="key">集合的键</param>
        /// <param name="members">要添加的成员</param>
        /// <returns>返回任务对象</returns>
        Task AddToSetAsync(string key, params string[] members);

        /// <summary>
        /// 异步从集合中移除指定成员
        /// </summary>
        /// <param name="key">集合的键</param>
        /// <param name="members">要移除的成员</param>
        /// <returns>返回任务对象</returns>
        Task RemoveFromSetAsync(string key, params string[] members);

        /// <summary>
        /// 异步检查集合中是否存在指定成员
        /// </summary>
        /// <param name="key">集合的键</param>
        /// <param name="member">要检查的成员</param>
        /// <returns>如果成员存在返回true，否则返回false</returns>
        Task<bool> IsSetMemberAsync(string key, string member);

        /// <summary>
        /// 异步将一个或多个成员及其分数添加到有序集合中
        /// </summary>
        /// <param name="key">有序集合的键</param>
        /// <param name="scoreMembers">成员及其分数</param>
        /// <returns>返回任务对象</returns>
        Task AddToSortedSetAsync(string key, params (double score, string member)[] scoreMembers);

        /// <summary>
        /// 异步从有序集合中移除指定成员
        /// </summary>
        /// <param name="key">有序集合的键</param>
        /// <param name="members">要移除的成员</param>
        /// <returns>返回任务对象</returns>
        Task RemoveFromSortedSetAsync(string key, params string[] members);

        /// <summary>
        /// 异步获取有序集合中指定范围内的成员
        /// </summary>
        /// <param name="key">有序集合的键</param>
        /// <param name="start">开始索引</param>
        /// <param name="stop">结束索引</param>
        /// <returns>返回有序集合中指定范围内的成员</returns>
        Task<string[]> GetSortedSetRangeByRankAsync(string key, long start, long stop);

        /// <summary>
        /// 异步获取有序集合中指定分数范围内的成员
        /// </summary>
        /// <param name="key">有序集合的键</param>
        /// <param name="min">最低分数</param>
        /// <param name="max">最高分数</param>
        /// <returns>返回有序集合中指定分数范围内的成员</returns>
        Task<string[]> GetSortedSetRangeByScoreAsync(string key, double min, double max);

        /// <summary>
        /// 异步设置指定键的过期时间
        /// </summary>
        /// <param name="key">要设置过期时间的键</param>
        /// <param name="expiry">过期时间</param>
        /// <returns>返回任务对象</returns>
        Task ExpireKeyAsync(string key, TimeSpan expiry);

        /// <summary>
        /// 异步获取指定键的剩余过期时间
        /// </summary>
        /// <param name="key">要获取剩余过期时间的键</param>
        /// <returns>返回键的剩余过期时间</returns>
        Task<TimeSpan?> GetKeyTimeToLiveAsync(string key);


        /// <summary>
        /// 异步增加指定键的值
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回增加后的值</returns>
        Task<long> IncrementAsync(string key);

        /// <summary>
        /// 异步减少指定键的值
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回减少后的值</returns>
        Task<long> DecrementAsync(string key);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Task<bool> SetAddAsync(string key, string value);
    }
}
